﻿using System;
using System.Net;
using System.Windows.Forms;
using Universal.WebAPI;
using Universal.WebAPI.Auth.Model;
using Universal.WebAPI.Auth.Services;

namespace UniversalAuth.TestClientWinforms
{
  public partial class Form1 : Form
  {

    public BaseClient client = new BaseClient("http://localhost:62828/");

    public Form1()
    {
      InitializeComponent();
    }

    private void cmdRegister_Click(object sender, EventArgs e)
    {
      var srv = new AccountService(client);
      

        var response =
          srv.RegisterUser(new RegistrationModel()
          {
            Email = textBox1.Text,
            Password = textBox2.Text,
            ConfirmPassword = textBox2.Text
          });

      if (response.Result.StatusCode == HttpStatusCode.OK)
      {
        MessageBox.Show("Completed");
      }
      
    }

    private async void cmdLogin_Click(object sender, EventArgs e)
    {

      var srv = new AccountService(client);
      var token = await srv.GetBearerToken(new LoginModel() { Username = "Test@Test.de", Password = "Test123!" });
      client.Token = token.AccessToken;

      var Userinfo = await srv.GetUserInfo();


      txtToken.Text += token.AccessToken;
      lblLogin.Text += Userinfo.Email;
      lblToken.Text += token.ExpiresAt;
    }
  }
}
